#代码 3-17 无序列表
class Node:
    def __init__(self,iterate):
        self.date=iterate
        self.next=None
    def setNext(self,newNext):
        self.next=newNext
    def getNext(self):
        return self.next
    def setDate(self,newdate):
        self.date=newdate
    def getDate(self):
        return self.date
class UnorderedList:
    def __init__(self):
        self.head=None
    def isEmpty(self):
        return self.head==None
    def add(self,item):
        temp=Node(item)
        temp.setNext(self.head)
        self.head=temp
    def length(self):
        current=self.head
        count=0
        while current!=None:
            count=count+1
            current=current.getNext()
        return count
    def search(self,item):
        current=self.head
        found=False
        while current!=None and not found:
            if current.getDate() == item:
                found=True
            else:
                current=current.getNext()
        return found
    def remove(self,item):
        current=self.head
        previous=None
        found=False
        while not found:
            if current.getDate()==item:
                found=True
            else:
                previous=current
                current=current.getNext()
        if previous==None:
            self.head=current.getNext()
        else:
            previous.setNext(current.getNext())

lt=UnorderedList()
lt.add(54)
lt.add(26)
lt.add(93)
lt.add(17)
lt.add(77)
lt.add(31)
print(lt.length())
print(lt.search(26))
print(lt.search(27))
print(lt.remove(54))
print(lt.remove(17))
print(lt.length())